/*
 * shader.h
 *
 *  Created on: Oct 14, 2012
 *      Author: travis
 *
 *	Shader Pool
 *
 *  Loading group or single of shader file, compile it and prepare to use.
 * 	Objects of this type are throwing exceptions.
 *
 */

#pragma once

#include <GLee.h>

#define NO_SDL_GLEXT

#ifdef _WIN32 
#include <windows.h> 
#endif

#include <GL/gl.h>
#include <fstream>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <vector>
#include <iostream>
//#include <dirent.h>
#include "console/globalConsole.h"
#include "engine/engineSettings.h"
#include "engine/RTSException.h"

namespace Shader
{

// global static class name
// included in thrown exception
const std::string type = "SHADER";

struct shaderInfo
{
	std::string fname;
	GLuint program, vs, fs;
};

class ShaderPool
{
public:
	ShaderPool();
	virtual ~ShaderPool();

	// throws an exception
	int loadFile(const char* fn, std::string& str);
	GLuint loadShader(std::string& source, GLuint mode);
	int initShader(std::string vname, std::string fname, std::string pname);
	//vertex file name, fragment file name, program file name (dir name)

	void clean();

	// throws an exception
	GLuint getProgramID(std::string filename);

	GLuint getFSID(std::string filename);
	GLuint getVSID(std::string filename);
	void useProgram(std::string filename);

	// throws an exception
	int loadDir();

	std::vector<shaderInfo> getShaders();
	int getCount();
private:
	std::vector<shaderInfo> files;

};

extern ShaderPool *sPool;
void initShaderPool();
void deleteShadePool();
}

